class LoginController < ApplicationController

  def index
    redirect_to :action => 'login'
  end

  def login
    if request.post?
      user = User.authenticate(params[:login], params[:password])
      if user
        session[:user_id] = user.id
        uri = session[:original_uri]
        session[:original_uri] = nil
        redirect_to(uri || { :controller => 'welcome' })
      else
        flash.now[:notice] = t(:invalid_login, :scope => 'flash')
      end
    else
      if current_user != nil
        redirect_to :controller => 'welcome'
      end
    end
  end

  def logout
    session[:user_id] = nil
    flash[:notice] = t(:logged_out, :scope => 'flash')
    redirect_to(:action => "login" )
  end

end
